package com.android.baseconfig.data;

import android.app.Application;
import android.content.Context;
import android.text.TextUtils;

import com.android.baseconfig.constact.AppConstant;
import com.android.baseconfig.constact.AppGlobalHost;
import com.android.baseconfig.data.http.AppNetDelegate;


/**
 * -----------------------------------------------------------------
 * Copyright (C) 2014-2016, by het, Shenzhen, All rights reserved.
 * -----------------------------------------------------------------
 * <p>
 * <p>描述：委托初始化App</p>
 * 名称: AppDelegate <br>
 * 作者: uuxia-mac<br>
 * 版本: 1.0<br>
 * 日期: 16/7/27 21:35<br>
 **/
public class AppDelegate {

    /**
     * Application实例对象
     **/
    private static Application app = null;

    /**
     * 初始化app
     **/
    public static void init(Application application) {
        app = application;
        AppNetDelegate.initOkHttps(application);
    }

    public static void initHttp(Application application) {
        app = application;
        AppNetDelegate.initOkHttp(application);
    }

    /**
     * 获取Application的Context
     **/
    public static Context getAppContext() {
        if (app == null) {
            return null;
        }
        return app.getApplicationContext();
    }

    /**
     * 设置Http请求baseUrl
     **/
    public static void setHost(String host) {
        if (TextUtils.isEmpty(host)) {
            return;
        }
        AppGlobalHost.setHostHttps(host);
    }

    public static void setCommHost(String host) {
        if (TextUtils.isEmpty(host)) {
            return;
        }
        AppGlobalHost.setCommHostHttps(host);
    }

    public static void setHostHttps(String host) {
        if (TextUtils.isEmpty(host)) {
            return;
        }
        AppGlobalHost.setHostHttps(host);
    }

    public static void setHostHttp(String host) {
        if (TextUtils.isEmpty(host)) {
            return;
        }
        AppGlobalHost.setHostHttp(host);
    }

    /**
     * 设置AppId
     **/
    public static void setAppId(String appId) {
        if (TextUtils.isEmpty(appId)) {
            return;
        }
        AppConstant.APPID = appId;
    }

    /**
     * 设置AppSecret
     **/
    public static void setAppSecret(String secret) {
        if (TextUtils.isEmpty(secret)) {
            return;
        }
        AppConstant.APP_SECRET = secret;
    }

    public static boolean isDebugHost() {
        if (AppGlobalHost.getHost() != null) {
            return AppGlobalHost.getHost().startsWith(AppGlobalHost.DEBUG_HOST);
        }
        return false;
    }

    public static boolean isTestHost() {
        if (AppGlobalHost.getHost() != null) {
            return AppGlobalHost.getHost().startsWith(AppGlobalHost.TEST_HOST);
        }
        return false;
    }

    public static boolean isReleaseHost() {
        if (AppGlobalHost.getHost() != null) {
            return AppGlobalHost.getHost().startsWith(AppGlobalHost.RELEASE_HOST);
        }
        return false;
    }

}
